#!/usr/bin/python 
# Run like so (or similar):
#	python build.py -build_samples -build_tests -xcode -debug


import sys
import os
import subprocess

os.chdir("build/")

buildSamples = "-BUILD_SAMPLES=OFF"
buildTests = "-BUILD_TESTS=OFF"
buildConfig = "-DCMAKE_BUILD_TYPE=Debug"

command = ["cmake"]
for arg in sys.argv:
	lower = arg.lower()
	if (lower == "-build_samples"):
		buildSamples = "-BUILD_SAMPLES=ON"
	elif (lower == "-build_tests"):
		buildTests = "-BUILD_TESTS=ON"
	elif (lower == "-debug"):
		buildConfig = "-DCMAKE_BUILD_TYPE=Debug";
	elif (lower == "-test"):
		buildConfig = "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
	elif (lower == "-release"):
		buildConfig = "-DCMAKE_BUILD_TYPE=Release"
	else:
		if (lower == "-xcode"):
			command.append("-G")
			command.append("Xcode")
		elif (lower == "-unix_make"):
			command.append("-G")
			command.append("Unix Makefiles")
		# This should be redone so that the clang path isn't hardcoded
		if lower == "-clang":
			command.append("-D")
			command.append("CMAKE_CXX_COMPILER=/usr/local/bin/clang")

command.append(buildTests)
command.append(buildSamples)
command.append(buildConfig)
command.append("../")

subprocess.call(command)
